{extend name="public:base"}
{block name="body"}
<body>
		<form class="layui-form layui-form-pane" action="">
			<div class="mainBox">
				<div class="main-container">
                    <div class="layui-row">
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">题目</label>
                                <div class="layui-input-block">
                                    <textarea name="topic" id="topic">{$info.topic|default=''}</textarea>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">知识点</label>
                                <div class="layui-input-block">
                                    <select name="knowledge_id" lay-search="{caseSensitive:false, fuzzy: true}">
                                        <option value="">请选择</option>
                                        {volist name="knowledge" id="vo"}
                                        <option value="{$vo.id}" {present name="info.knowledge_id"} {eq name="info.knowledge_id" value="$vo['id']"} selected {/eq} {/present}>{$vo.title}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">题组类目</label>
                                <div class="layui-input-block">
                                    <select name="type_id">
                                        <option value="">请选择</option>
                                        {volist name="type" id="vo"}
                                        <option value="{$vo.id}" {present name="info.type_id"} {eq name="info.type_id" value="$vo['id']"} selected {/eq} {/present}>{$vo.name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">题型</label>
                                <div class="layui-input-block">
                                    <select name="cate">
                                        <option value="">请选择</option>
                                        <option value="1" {present name="info.cate"} {eq name="info.cate" value="1"} selected {/eq} {/present}>填空题</option>
                                        <option value="2" {present name="info.cate"} {eq name="info.cate" value="2"} selected {/eq} {/present}>单选题</option>
                                        <option value="3" {present name="info.cate"} {eq name="info.cate" value="3"} selected {/eq} {/present}>多选题</option>
                                        <option value="4" {present name="info.cate"} {eq name="info.cate" value="4"} selected {/eq} {/present}>简单题</option>
                                        <option value="5" {present name="info.cate"} {eq name="info.cate" value="5"} selected {/eq} {/present}>计算题</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm12 layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">选项&填空</label>
                                <div class="layui-input-block">
                                    <div style="padding:10px;color:rgb(141, 143, 145)">注释:一行一个</div>
                                    <textarea name="item" class="layui-textarea" row="6"  style="height:240px;">{$info.item_str|default=''}</textarea>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">答案</label>
                                <div class="layui-input-block">
                                    <textarea name="answer" id="answer">{$info.answer|default=''}</textarea>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">讲解释义</label>
                                <div class="layui-input-block">
                                    <textarea name="explain" id="explain">{$info.explain|default=''}</textarea>
                                </div>
                            </div>
                        </div>                                             
                    </div>
                </div>
            </div>
            <div class="bottom">
            <div class="button-container">
                <input type="hidden" name="id" value="{$info.id|default=''}">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
            </div>
		</form>
	</body>
{/block}
{block name="script"}
<script>
    layui.use(['jquery','form','upload','tinymce'], function() {
        let form = layui.form;
        let $ = layui.jquery;
        let tinymce = layui.tinymce;
        let select = layui.select;
        var topic = tinymce.render({
					elem: "#topic",
					height: 200,
                    contextmenu:false,
                    plugins:'code kityformula-editor image table hr imagetools',
                    images_upload_url:"{:url('ajax/upload')}",
                    form:{name:"file"},
                    convert_urls:false,
                    statusbar:false,
                    menubar:false,
                    toolbar:'code  kityformula-editor forecolor backcolor bold italic underline strikethrough image table fontsizeselect',
                    valid_elements : 'img[src|style=max-width:100%],strong/b,div,p,span'
				});
        var answer = tinymce.render({
                elem: "#answer",
                height: 200,
                contextmenu:false,
                plugins:'code kityformula-editor image table hr imagetools',
                images_upload_url:"{:url('ajax/upload')}",
                form:{name:"file"},
                convert_urls:false,
                statusbar:false,
                menubar:false,
                toolbar:'code  kityformula-editor forecolor backcolor bold italic underline strikethrough image table fontsizeselect',
                valid_elements : 'img[src|style=max-width:100%],strong/b,div,p,span'
            });
        var explain = tinymce.render({
                elem: "#explain",
                height: 200,
                contextmenu:false,
                plugins:'code kityformula-editor image table hr imagetools',
                images_upload_url:"{:url('ajax/upload')}",
                form:{name:"file"},
                convert_urls:false,
                statusbar:false,
                menubar:false,
                toolbar:'code  kityformula-editor forecolor backcolor bold italic underline strikethrough image table fontsizeselect',
                valid_elements : 'img[src|style=max-width:100%],strong/b,div,p,span'
            });
        form.on('submit(form-save)', function(data) {
            $('[name="topic"]').html( topic.getContent());
            $('[name="answer"]').html( answer.getContent());
            $('[name="explain"]').html( explain.getContent());
            $.ajax({
                url: '{:url("edit")}',
                data: $('.layui-form').serialize(),
                type: 'post',
                success: function(result) {
                    if (result.code == 1) {
                        layer.msg('操作成功', {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                            parent.layui.table.reload("table-list");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
{/block}